<template>
	<BaseContainer>
		<aplid-base-crud ref="crud" class="w-100" v-bind="baseConfig">
			<template #detailDialog="{ row }">
				<DetailPart :nowRowData="row"></DetailPart>
			</template>
			<template #taskId="{ row }">
				<el-tooltip v-if="row.daysLeftToExpire&&row.taskStatus!='ENDED'" effect="dark" :content="judgeTiop(row.daysLeftToExpire)" placement="bottom">
					<span style="color: red">{{ row.taskId }}</span>
				</el-tooltip>
				<span v-else>{{ row.taskId }}</span>
			</template>
			<!-- 审批 -->
			<template #approvalDialog="{ row }">
				<PreviewTable :is-read="true" :data="row.metadataJson"></PreviewTable>
				<div class="btn_part">
					<el-button @click="toSure(row, 'REJECT')">驳回</el-button>
					<el-button type="primary" @click="toSure(row, 'PASS')">通过</el-button>
				</div>
			</template>
		</aplid-base-crud>
	</BaseContainer>
</template>

<script setup lang="ts">
import { baseConfig } from './config'
import DetailPart from '../detailPart/index.vue'
import PreviewTable from '@/views/governmentAffairs/overallTask/previewTable/index.vue'
import apiMod from '@/apiMod/index'

let crud = ref()
//  处理刷新
const handleRefresh = (query?: any) => {
	nextTick(() => {
		crud.value.refreshChange(query)
	})
}
const toSure = (row, type) => {
	let params = {
		id: row.id,
		eventEnum: type,
		taskStatus: 'PENDING_APPROVAL',
		taskStatusLabel: '待审批',
		metadataJson: JSON.stringify(row.metadataJson),
	}
	apiMod.view_zwglTaskInfo_approval(params).then((res) => {
		//关闭弹窗，刷新页面
		if (res.code == 0) {
			ElMessage.success('操作成功')
			handleRefresh()
		}
	})
}
const judgeTiop = (data) => {
	if (Number(data) > 0) {
		return `距离过期剩余${data}天`
	} else if (Number(data) < 0) {
		return `已过期${Math.abs(data)}天`
	} else if (Number(data) == 0) {
		return '今天过期'
	} else {
		return '已过期'
	}
}
</script>

<style scoped lang="scss">
.btn_part {
	width: 100%;
	display: flex;
	flex-direction: row;
	justify-content: center;
	margin-top: 30px;
}
</style>
